const fs = require("fs");
const { parse } = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const generate = require("@babel/generator").default;
const template = require("@babel/template").default;

const analyseFile = (filename) => {
  const file = fs.readFileSync(filename, "utf-8");

  const ast = parse(file, {
    sourceType: "module",
  });

  traverse(ast, {
    VariableDeclaration({ node }) {
      if (node.kind === "const" || node.kind === "let") {
        node.kind = "var";
      }
    },
    ArrowFunctionExpression({ node }) {
      node.type = "FunctionDeclaration";
    },
    ClassDeclaration({ node }) {},
  });

  const { code } = generate(ast);
  console.log(code);
};
analyseFile("./src/es6.js");
